const { observable, action } = require('mobx-miniprogram');

// PLM角色模拟器状态管理
module.exports.plmRoleSimulatorStore = observable({
  // 角色列表
  roleList: [
    { id: 'r001', name: '产品经理', permissions: ['create_project', 'edit_project', 'view_report'] },
    { id: 'r002', name: '研发工程师', permissions: ['edit_project', 'submit_code', 'view_task'] },
    { id: 'r003', name: '测试工程师', permissions: ['create_test', 'view_task', 'report_bug'] },
    { id: 'r004', name: '项目经理', permissions: ['*'] },
    { id: 'r005', name: '普通用户', permissions: ['view_project'] }
  ],
  
  // 当前角色
  currentRole: null,
  
  // 切换角色
  switchRole: action(function(roleId) {
    const role = this.roleList.find(item => item.id === roleId);
    if (role) {
      this.currentRole = role;
      return true;
    }
    return false;
  }),
  
  // 检查权限
  hasPermission: action(function(permission) {
    if (!this.currentRole) return false;
    
    // 如果角色有全部权限
    if (this.currentRole.permissions.includes('*')) return true;
    
    // 检查特定权限
    return this.currentRole.permissions.includes(permission);
  }),
  
  // 重置角色
  resetRole: action(function() {
    this.currentRole = null;
  })
}); 